﻿using System;
using System.Threading;
using System.Web.UI;


namespace NetDon.OA.Portal.Controls
{
    [ControlValueProperty("Text")]
    public partial class Calendar : UserControlBase
    {
        public string Text
        {
            get { return txtDate.Text; }
            set { txtDate.Text = value; }
        }

        public DateTime? Value
        {
            //get
            //{
            //    return string.IsNullOrEmpty(Text)
            //               ? (DateTime?) null
            //               : DateTime.ParseExact(Text, SystemConfiguration.DateFormat,
            //                                     Thread.CurrentThread.CurrentUICulture.DateTimeFormat);
            //}
            //set { Text = value.HasValue ? value.Value.ToString(SystemConfiguration.DateFormat) : string.Empty; }
            get
            {
                return string.IsNullOrEmpty(Text)
                           ? (DateTime?)null
                           : DateTime.ParseExact(Text, "yyyy-MM-dd",
                                                 Thread.CurrentThread.CurrentUICulture.DateTimeFormat);
            }
            set { Text = value.HasValue ? value.Value.ToString("yyyy-MM-dd") : string.Empty; }
        }   

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CalendarExtender1.Format ="yyyy-MM-dd"; 
            }
        }
    }
}